﻿using System;

namespace DreamCube.Framework.Utilities.Report
{
    public class SearchCondition : Element
    {
        #region "字段"

        private static String html = "<tr><td class='titleTD'>{0}</td><td>{1}</td></tr>";

        private static String inputHtml = "<input type='text' FieldName='{0}' TableID='{1}' />";
        private static String comboboxHtml = "<input type='text' FieldName='{0}' TableID='{1}' />";

        #endregion

        #region "属性"

        /// <summary>
        /// 字段名
        /// </summary>
        public String FieldName
        {
            get;
            set;
        }

        /// <summary>
        /// 字段标签名
        /// </summary>
        public String FieldLabelName
        {
            get;
            set;
        }

        /// <summary>
        /// 搜索控件类型，直接输入型，下拉选择型
        /// </summary>
        public Enums.SearchCtrlType SearchCtrlType
        {
            get;
            set;
        }

        /// <summary>
        /// 下拉选择的数据源
        /// </summary>
        public String DropDownDataSource
        {
            get;
            set;
        }

        /// <summary>
        /// 所属的列表的ID值
        /// </summary>
        public String TableID
        {
            get;
            set;
        }

        #endregion

        #region "方法"

        /// <summary>
        /// 生成html
        /// </summary>
        /// <returns></returns>
        public override String ToHtml()
        {
            String html = base.ToHtml();
            html += String.Format(SearchCondition.html, this.FieldLabelName, MakeHtml(this.SearchCtrlType, this.FieldName, this.TableID));
            return html;
        }

        #endregion

        #region "私有方法"

        /// <summary>
        /// 构造Html文本
        /// </summary>
        /// <param name="SearchCtrlType">控件类型</param>
        /// <param name="fieldName">搜索的字段名</param>
        /// <returns></returns>
        private static String MakeHtml(Enums.SearchCtrlType searchCtrlType, String fieldName, String tableID)
        {
            switch (searchCtrlType)
            {
                case Enums.SearchCtrlType.Input :
                    return String.Format(inputHtml, fieldName, tableID);
            }
            return String.Empty;
        }

        #endregion
    }
}
